{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "\n",
    "with open('/home/husein/ssd3/summarization/summarization.json') as fopen:\n",
    "    summarization = json.load(fopen)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['JOHANNESBURG 27 April - Hujan lebat berterusan melanda utara Mozambique hari ini, menyebabkan angka kematian meningkat kepada lima orang.\\n\\nLapor Reuters, hujan lebat yang berlaku mencetuskan kebimbangan berlakunya banjir selepas Puting Beliung Kenneth melanda kawasan pantai, menghancurkan bangunan dan memutuskan sistem komunikasi dua hari lalu.\\n\\nSementara itu, agensi bantuan dilaporkan mengalami kesukaran untuk menghulurkan bantuan ekoran banyak kawasan tidak dapat diakses. - AGENSI',\n",
       " 'Hujan lebat di utara Mozambique menyebabkan kematian lima orang dan memicu kekhawatiran akan banjir setelah Puting Beliung Kenneth menghancurkan bangunan dan memutuskan sistem komunikasi. Agensi bantuan mengalami kesulitan dalam memberikan bantuan karena banyak daerah tidak dapat diakses.']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "summarization[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "templates = [\n",
    "    'paragraph `{t}`, summarize the paragraph',\n",
    "    'paragraph `{t}`, ringkaskan paragraph',\n",
    "    'ringkaskan teks `{t}`',\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "template = {\n",
    "    \"description\": \"Template used by Alpaca-LoRA.\",\n",
    "    \"prompt_input\": \"Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n{instruction}\\n\\n### Input:\\n{input}\\n\\n### Response:\\n\",\n",
    "    \"prompt_no_input\": \"Below is an instruction that describes a task. Write a response that appropriately completes the request.\\n\\n### Instruction:\\n{instruction}\\n\\n### Response:\\n\",\n",
    "    \"response_split\": \"### Response:\"    \n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random\n",
    "\n",
    "data = []\n",
    "for d in summarization:\n",
    "    try:\n",
    "        t = d[0]\n",
    "        a = d[1]\n",
    "        q = random.choice(templates).format(t = t)\n",
    "        res = template[\"prompt_no_input\"].format(instruction=q)\n",
    "        res = f\"{res}{a}\"\n",
    "        data.append(res)\n",
    "\n",
    "    except Exception as e:\n",
    "        print(e)\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "with open('prepared-summarization.json', 'w') as fopen:\n",
    "    json.dump(data, fopen)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
